package com.zhuiYun.project.api.sysUser.mapper;

import com.zhuiYun.project.api.sysUser.entiy.Power;
import com.zhuiYun.project.api.sysUser.entiy.SysUser;
import com.zhuiYun.project.common.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName SysUserMapper
 * @Description TODO
 * @Author zcy
 * @Date 2023/3/27 10:46
 **/
@Mapper
public interface SysUserMapper extends BaseMapper<SysUser> {
    @Delete("delete from sys_user_power where user_id = #{userId}")
    int delPower(Integer userId);
    @Insert("<script>" +
            " " +
            " insert into sys_user_power(user_id,menu_id)" +
            " values<foreach collection='integers' item='a' separator=','>(#{userId},#{a})</foreach>;" +
            " " +
            "</script>")
    void userPower(Integer userId, List<Integer> integers);
    @MapKey("alias")
    @Select("SELECT concat(b.menu_alias,':',a.menu_alias) alias FROM sys_menu a LEFT JOIN sys_menu b on a.parent_id = b.id where a.menu_type = 2 and a.id in (select c.menu_id id from sys_user_power c where user_id = #{id} )")
    Map<String, Power> getPowerByUser(Integer id);
    @Select("select menu_id from sys_user_power where user_id = #{userId}")
    List<String> getUserPower(Integer userId);
}
